<?php
/*
 * 店内助手音频上传接口
 */
require_once dirname(dirname(__FILE__)) . '/include/common.inc.php';
require_once INCLUDE_ROOT_PATH . 'file_server.class.php';

$act = isset($_REQUEST['act']) ? $_REQUEST['act'] : '';	//操作，upload上传，delete删除
$filename = isset($_REQUEST['filename']) ? $_REQUEST['filename'] : '';	//要操作的文件名
$token = isset($_REQUEST['token']) ? $_REQUEST['token'] : '';	//token验证
if (($act == 'upload' && empty($_FILES))
    || ($act == 'delete' && empty($filename))
    || ($act == 'view' && empty($filename))
    || $token != md5('shopassistantupload'))
{
	$result = false;
}
else
{
	$filepath = SHOPASSISTANT_AUDIO_ROOT_PATH ;
	$File_server = new File_server();
	switch ($act)
	{
		case 'upload':
			$result = $File_server->upload($filepath, 256);//256M
			break;

		case 'delete':
			$del_filepath = $filepath . $filename;
			if (is_file($del_filepath))
			{
				$result = $File_server->delete($del_filepath);
			}
			break;
		case 'view':
			$fetch_filepath = $filepath . $filename;
			if (is_file($fetch_filepath))
			{
				$result = $File_server->view_audio($fetch_filepath);
				exit;
			}
			break;

		default:
			$result = false;
			break;
	}
}


echo json_encode($result);
?>